/**
* Class to manage an 'update where' on a table to be executed in the Servlet
* This function works like:
* query=update users set description='System Administrator' where code='manzanot'
* An example of the call is:
* http://localhost:3141/idbcrownINServer/idbcrownINServer?action=UPDATE_WHERE&query=update users set description='System Administrator' where code='manzanot'
*
* Project: idbCrownInServer
* Author:  TM
* Date:    05/04/2013
*
* History
* ------------------
* 05/04/2013 - TM - Initial version.
*/
 
 
package Functions;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import Application.*;
import DataModel.*;

public class update_where extends genericFunction
{
    /** Class attributes */
    protected libSQLUtil sqlUtil;
    /** Application support */
    protected static libApplication appSupport;


     /** Constructor  */
    public update_where(HttpServletRequest _request, HttpServletResponse _response) throws IOException, ServletException
    {
       super(_request, _response);
       appSupport = libApplication.getInstance();
    }
    
    /** Execute function */
    public String execute()
    {
      String     result   = "";
      String     query    = getRequest().getParameter("query");
      int        rows     = -1;
      try
      {
        sqlUtil  = libSQLUtil.getInstance();
        rows     = sqlUtil.Update(query);
        
        result = "" + rows;
        
        if ((result == null) || (result.equals("-1")))
           sendError();
        else  
           sendResponse(result);
      }
      catch(Exception ex)
      {
        sendError(ex);
      }
      return result;
    }
}